/*!
 * jQuery Carousel Plugin v1.0.1
 * Original author: Juven Pajares
 * Licensed under the MIT license
 */
 
// the semi-colon before the function invocation is a safety
// net against concatenated scripts and/or other plugins
// that are not closed properly.
;(function ($, window, document, undefined) {

    // undefined is used here as the undefined global
    // (i.e. it can be changed by someone else). undefined isn't really
    // being passed in so we can ensure that its value is truly undefined.
 
    // window and document are passed through as local
    // variables rather than as globals, because this (slightly)
    // quickens the resolution process and can be more
    // efficiently minified (especially when both are
    // regularly referenced in your plugin).
 
    // Create the defaults once
    var pluginName = 'carousel',
        defaults = {
            boxes: '.defaultBoxes',
			layer2: 80,
			layer3: 160,
			duration: 600,
			easing: 'swing'
        };
 
    // The actual plugin constructor
    function Plugin(element, options) {
        this.element = element;

        // jQuery has an extend method that merges the
        // contents of two or more objects, storing the
        // result in the first object. The first object
        // is generally empty because we don't want to alter
        // the default options for future instances of the plugin
        this.options = $.extend({}, defaults, options) ;
        this._defaults = defaults;
        this._name = pluginName;
        this.init();
    }
 
    Plugin.prototype.init = function () {
		// Place initialization logic here
		// You already have access to the DOM element and
		// the options via the instance, e.g. this.element
		// and this.options
		// calling default settings will be ex. options.boxes,
		// this will return the value of boxes
		// this section will execute after the dom is loaded
		// try removing the comment below to test the output
		// alert (this.options.boxes);
 		var thisBox = $(this.options.boxes);
			var slidespeed = 500;
			var duration = this.options.duration;
			var easing = this.options.easing;
			var scale100 = {'-webkit-transform': 'scale(1)', '-moz-transform': 'scale(1)', 'zIndex': '3'};
			var scale80 = {'-webkit-transform': 'scale(0.8)', '-moz-transform': 'scale(0.8)', 'zIndex': '2'};
			var scale60 = {'-webkit-transform': 'scale(0.6)', '-moz-transform': 'scale(0.6)', 'zIndex': '1'};
			var scale40 = {'-webkit-transform': 'scale(0.4)', '-moz-transform': 'scale(0.4)', 'zIndex': '0'};
			var newXpos = parseInt(thisBox.parent().css('width'))/2 -parseInt(thisBox.css('width'))/2;
			var newYpos = parseInt(thisBox.parent().css('height'))/2 -parseInt(thisBox.css('height'))/2;
			var nYpos = newYpos - 0;
			var nXpos1 = newXpos - 0;
			var nXpos2 = newXpos - this.options.layer2;
			var nXpos3 = newXpos - -this.options.layer2;
			var nXpos4 = newXpos - this.options.layer3;
			var nXpos5 = newXpos - -this.options.layer3;
			var nYpos = newYpos - 0;
			var pos1 = {left: nXpos1, top: nYpos};
			var pos2 = {left: nXpos2, top: nYpos};
			var pos3 = {left: nXpos3, top: nYpos};
			var pos4 = {left: nXpos4, top: nYpos};
			var pos5 = {left: nXpos5, top: nYpos};
			var easeout = {duration: duration, easing: easing};
		if (thisBox.length == 6) {
		thisBox.each(function() {
			if ($(this).is(':first-child')) {
				$(this).css(scale100).css(pos1);
			}
			else if ($(this).is(':nth-child(2)')) {
				$(this).css(scale80).css(pos2).fadeTo('fast', 0.8);
			}
			else if ($(this).is(':nth-child(3)')) {
				$(this).css(scale60).css(pos4).fadeTo('fast', 0.6);
			}
			else if ($(this).is(':nth-child(4)')) {
				$(this).css(scale40).css(pos1).fadeTo('fast', 0.4);
			}
			else if ($(this).is(':nth-child(5)')) {
				$(this).css(scale60).css(pos5).fadeTo('fast', 0.6);
			}
			else if ($(this).is(':last-child')) {
				$(this).css(scale80).css(pos3).fadeTo('fast', 0.8);
			}
		});
		thisBox.live('click', function() {
			var child6 = $(this).parent().find(':last-child');
			var child5 = $(this).parent().find(':nth-child(5)');
			var child4 = $(this).parent().find(':nth-child(4)');
			var child3 = $(this).parent().find(':nth-child(3)');
			var child2 = $(this).parent().find(':nth-child(2)');
			var child1 = $(this).parent().find(':first-child');
			if ($(this).is(':last-child')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child1.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos2, easeout);
				});
				child2.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos4, easeout);
				});
				child3.each(function() {
					$(this).css(scale40).fadeTo('fast', 0.4);
					$(this).animate(pos1);
				});
				child4.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos5, easeout);
				});
				child5.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos3, easeout);
				});
			}
			else if ($(this).is(':nth-child(5)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child6.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos2, easeout);
				});
				child1.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos4, easeout);
				});
				child2.each(function() {
					$(this).css(scale40).fadeTo('fast', 0.4);
					$(this).animate(pos1);
				});
				child3.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos5, easeout);
				});
				child4.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos3, easeout);
				});
			}
			else if ($(this).is(':nth-child(4)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child5.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos2, easeout);
				});
				child6.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos4, easeout);
				});
				child1.each(function() {
					$(this).css(scale40).fadeTo('fast', 0.4);
					$(this).animate(pos1);
				});
				child2.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos5, easeout);
				});
				child3.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos3, easeout);
				});
			}
			else if ($(this).is(':nth-child(3)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child4.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos2, easeout);
				});
				child5.each(function() {
					$(this).animate(pos4, easeout);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child6.each(function() {
					$(this).css(scale40).fadeTo('fast', 0.4);
					$(this).animate(pos1);
				});
				child1.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos5, easeout);
				});
				child2.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos3, easeout);
				});
			}
			else if ($(this).is(':nth-child(2)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child3.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos2, easeout);
				});
				child4.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos4, easeout);
				});
				child5.each(function() {
					$(this).css(scale40).fadeTo('fast', 0.4);
					$(this).animate(pos1);
				});
				child6.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos5, easeout);
				});
				child1.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos3, easeout);
				});
			}
			else if ($(this).is(':first-child')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child2.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos2, easeout);
				});
				child3.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos4, easeout);
				});
				child4.each(function() {
					$(this).css(scale40).fadeTo('fast', 0.4);
					$(this).animate(pos1);
				});
				child5.each(function() {
					$(this).css(scale60).fadeTo('fast', 0.6);
					$(this).animate(pos5, easeout);
				});
				child6.each(function() {
					$(this).css(scale80).fadeTo('fast', 0.8);
					$(this).animate(pos3, easeout);
				});
			}
		});
		}
		else if (thisBox.length == 5) {
		thisBox.each(function() {
			if ($(this).is(':first-child')) {
				$(this).css(scale100).css(pos1);
			}
			else if ($(this).is(':nth-child(2)')) {
				$(this).css(scale80).css(pos2).fadeTo('fast', 0.8);
			}
			else if ($(this).is(':nth-child(3)')) {
				$(this).css(scale80).css(pos3).fadeTo('fast', 0.8);
			}
			else if ($(this).is(':nth-child(4)')) {
				$(this).css(scale60).css(pos4).fadeTo('fast', 0.6);
			}
			else if ($(this).is(':last-child')) {
				$(this).css(scale60).css(pos5).fadeTo('fast', 0.6);
			}
		});
		thisBox.live('click', function() {
			var child5 = $(this).parent().find(':last-child');
			var child4 = $(this).parent().find(':nth-child(4)');
			var child3 = $(this).parent().find(':nth-child(3)');
			var child2 = $(this).parent().find(':nth-child(2)');
			var child1 = $(this).parent().find(':first-child');
			if ($(this).is(':last-child')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child3.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child1.each(function() {
					$(this).animate(pos4);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child2.each(function() {
					$(this).animate(pos5);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child4.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':nth-child(4)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child5.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child3.each(function() {
					$(this).animate(pos4);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child1.each(function() {
					$(this).animate(pos5);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child2.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':nth-child(3)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child1.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child2.each(function() {
					$(this).animate(pos4);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child4.each(function() {
					$(this).animate(pos5);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child5.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':nth-child(2)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child4.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child5.each(function() {
					$(this).animate(pos4);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child3.each(function() {
					$(this).animate(pos5);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child1.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':first-child')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child2.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child4.each(function() {
					$(this).animate(pos4);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child5.each(function() {
					$(this).animate(pos5);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child3.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
		});
		}
		else if (thisBox.length == 4) {
		thisBox.each(function() {
			if ($(this).is(':first-child')) {
				$(this).css(scale100).css(pos1);
			}
			else if ($(this).is(':nth-child(2)')) {
				$(this).css(scale80).css(pos2).fadeTo('fast', 0.8);
			}
			else if ($(this).is(':nth-child(3)')) {
				$(this).css(scale80).css(pos3).fadeTo('fast', 0.8);
			}
			else if ($(this).is(':last-child')) {
				$(this).css(scale40).css(pos1).fadeTo('fast', 0.4);
			}
		});
		thisBox.live('click', function() {
			var child4 = $(this).parent().find(':last-child');
			var child3 = $(this).parent().find(':nth-child(3)');
			var child2 = $(this).parent().find(':nth-child(2)');
			var child1 = $(this).parent().find(':first-child');
			if ($(this).is(':last-child')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child3.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child1.each(function() {
					$(this).animate(pos1);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child2.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':nth-child(3)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child1.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child2.each(function() {
					$(this).animate(pos1);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child4.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':nth-child(2)')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child4.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child3.each(function() {
					$(this).animate(pos1);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child1.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':first-child')) {
				$(this).animate(pos1);
				$(this).css(scale100).fadeTo('fast', 1);
				child2.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child4.each(function() {
					$(this).animate(pos1);
					$(this).css(scale60).fadeTo('fast', 0.6);
				});
				child3.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
		});
		}
		else if (thisBox.length == 3) {
		thisBox.each(function() {
			if ($(this).is(':first-child')) {
				$(this).css(scale100).css(pos1);
			}
			else if ($(this).is(':nth-child(2)')) {
				$(this).css(scale80).css(pos2).fadeTo('fast', 0.8);
			}
			else if ($(this).is(':last-child')) {
				$(this).css(scale80).css(pos3).fadeTo('fast', 0.8);
			}
		});
		thisBox.live('click', function() {
			var child3 = $(this).parent().find(':last-child');
			var child2 = $(this).parent().find(':nth-child(2)');
			var child1 = $(this).parent().find(':first-child');
			if ($(this).is(':last-child')) {
				$(this).animate(pos1);
				$(this).css('zIndex', '6').fadeTo('fast', 1);
				$(this).css(scale100);
				child1.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child2.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':nth-child(2)')) {
				$(this).animate(pos1);
				$(this).css('zIndex', '6').fadeTo('fast', 1);
				$(this).css(scale100);
				child3.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child1.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
			else if ($(this).is(':first-child')) {
				$(this).animate(pos1);
				$(this).css('zIndex', '6').fadeTo('fast', 1);
				$(this).css(scale100);
				child2.each(function() {
					$(this).animate(pos2);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
				child3.each(function() {
					$(this).animate(pos3);
					$(this).css(scale80).fadeTo('fast', 0.8);
				});
			}
		});
		}
    };
 
    // A really lightweight plugin wrapper around the constructor,
    // preventing against multiple instantiations
    $.fn[pluginName] = function (options) {
        return this.each(function () {
            if (!$.data(this, 'plugin_' + pluginName)) {
                $.data(this, 'plugin_' + pluginName,
                new Plugin( this, options ));
            }
        });
    }
})(jQuery, window, document);